<?php
/**
 * 默认展示页面
 * @copyright  Copyright (c) 2014-2015 TuntronKJ Inc. (http://www.tuntron.com)
 * @license    http://www.tuntron.com
 * @link       http://www.tuntron.com
 * @since      File available since Release v1.1
 */
defined('InTuntronKJ') or exit('Access Invalid!');
class indexControl extends BaseHomeControl{
	public function indexOp(){
		$model_bank = Model('bank');
		$model_article = Model('article');
		$model_user = Model('member');
		
		$userinfo = $model_user->getMemberInfo(array('uid'=>$_SESSION['uid']));
		$paymentinfo = $model_bank->getPaymentInfo(array('uid'=>$_SESSION['uid']));
		$bankifno = $model_bank->getBankInfo(array('id'=>$paymentinfo['bankId']));				

		//用户信息
		$param = array();
		$param['userType'] = $userinfo['type'];
		$param['userPaymentType'] = $bankifno['id'];
		$param['userPaymentTypeName'] = $bankifno['name'];
		$param['userAccName'] = $paymentinfo['username'];
		$param['userAccNo'] = $paymentinfo['account'];		
		
		
		//获取公告通知
		$articles = array();		
		$article_list = $model_article->getArticleList(array('ac_id'=>1));
		if(!empty($article_list) && is_array($article_list)){
			foreach($article_list as $key=>$value){
				$article[$key]['Id'] = $value['article_id'];
				$article[$key]['Content'] = $value['article_content'];
				$article[$key]['Priority'] = 0;
				$article[$key]['SortOrder'] = null;
				$article[$key]['LastModifiedID'] = 1;
				$article[$key]['DateInserted'] = date('Y-m-d H:i:s', $value['article_time']);
				$article[$key]['DateModified'] = date('Y-m-d H:i:s', $value['article_time']);
				$article[$key]['Enabled'] = false;
				$article[$key]['Title'] = $value['article_title'];
				$article[$key]['CreatedUser'] = 'admin';
				$article[$key]['UpdatedUser'] = 'admin';
			}
		}
		$json = json_encode($article);

		Language::read('home_index_index');
		Tpl::output('json',$json);
		Tpl::output('param',$param);
		Tpl::output('index_sign','index');
		Tpl::showpage('index');
	}


	//json最新一个开奖记录
	public function GetScheduleAndIssueNumberOp() {
	
		$typeid=intval($_GET['typeid']);

		if ($typeid > 0){

			$today=date('Y-m-d', time());
			$today_time=date('Y-m-d H:i:s', time());
			$model_data	= Model('data_class');
			$model_kjtype = Model('kjtype');

			//获取即将开奖期数以及时间
			$thisNoType = $model_data->getGameNo($typeid);

			//获取上次开奖期数以及时间
			$thisLastNoType = $model_kjtype->getGameLastNo($typeid);

			if(!$thisLastNoType){
				echo json_encode("fail");
				exit();
			}

			//获取最后一期开奖数据，注意限制未开奖数据加载
			$last_data = $model_data->getList(array('type' => $typeid, 'number'=>date('Ymd', time()).'-'.sprintf("%03d",$thisLastNoType['actionNo'])), 1, 1);
			$one_last_data = $last_data[0];			
			$differ=strtotime($today.' '.$thisNoType['actionTime'])-time();
			//$lastNo['kjdTime']=$this->getTypeFtime($type);

			if(time()-strtotime($today.' '.$thisLastNoType['actionTime'])<20){
				$one_last_data['data'] = '';
			}

			$josn_data = array('issue_number' =>date('Ymd', time()).'-'.sprintf("%03d",$thisNoType['actionNo']),'lottery_time'=>$today.' '.$thisNoType['actionTime'],'lottery_get_time'=>$today_time,'differ'=>$differ,'advance'=>60,'preIssueNumber'=>$one_last_data['number'] ,'preBonusNumber'=>$one_last_data['data']);

			echo json_encode($josn_data);
			exit();

		}
	}

	//json输出分类
	public function josn_classOp() {
		/**
		 * 实例化商品分类模型
		 */
		$model_class		= Model('goods_class');
		$goods_class		= $model_class->getClassList(array('gc_parent_id'=>intval($_GET['gc_id']),'order'=>'gc_parent_id asc,gc_sort asc,gc_id asc'));
		$array				= array();
		if(is_array($goods_class) and count($goods_class)>0) {
			foreach ($goods_class as $val) {
				$array[$val['gc_id']] = array('gc_id'=>$val['gc_id'],'gc_name'=>htmlspecialchars($val['gc_name']),'gc_parent_id'=>$val['gc_parent_id'],'gc_sort'=>$val['gc_sort']);
			}
		}
		/**
		 * 转码
		 */
		if (strtoupper(CHARSET) == 'GBK'){
			$array = Language::getUTF8(array_values($array));//网站GBK使用编码时,转换为UTF-8,防止json输出汉字问题
		} else {
			$array = array_values($array);
		}
		echo $_GET['callback'].'('.json_encode($array).')';
	}

	//判断是否登录
	public function loginOp(){
		echo ($_SESSION['is_login'] == '1')? '1':'0';
	}

}
